package com.adamjwh.pratice.offer;

/**
 * 给定一个double类型的浮点数base和int类型的整数exponent。求base的exponent次方。
 */
public class ThePowerOfBase {
    public double Power(double base, int exponent) {
        double result = 1;

        if(exponent < 0) {
            exponent = -exponent;
            while(exponent-- != 0) {
                result *= base;
            }
            result = 1 / result;
        } else {
            while (exponent-- !=0) {
                result *= base;
            }
        }

        return result;
    }
}
